﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Tosi
{
    public partial class MapConfForm : Form
    {
        public MapConfForm()
        {
            InitializeComponent();
            for (int i = 0; i < Var.JncNumber; i++)
            {
                string str = "";
                str += i;
                str += " - " + Var.JncName[i];
                comboBox1.Items.Add(str);
            }
            for (int i = 0; i < Var.StrNumber; i++)
            {
                string str = "";
                str += i;
                str += " - " + Var.StrName[i];
                comboBox2.Items.Add(str);
            }
            for (int i = 0; i < Var.JncNumber; i++)
            {
                string str = "";
                str += i;
                str += " - " + Var.JncName[i];
                comboBox3.Items.Add(str);
            }
            for (int i = 0; i < Var.JncNumber; i++)
            {
                string str = "";
                str += i;
                str += " - " + Var.JncName[i];
                comboBox4.Items.Add(str);
            }
            
        }

        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            string str = "";
            str += Var.JncName[comboBox1.SelectedIndex];
            textBox2.Text = str;
            str = "";
            str += Var.JncArr[comboBox1.SelectedIndex, 0];
            textBox3.Text = str;
            str = "";
            str += Var.JncArr[comboBox1.SelectedIndex, 1];
            textBox4.Text = str;
            button4.Enabled = true;
            button5.Enabled = true;
        }

        private void button4_Click(object sender, EventArgs e)
        {
            string str = "";
            str += Var.JncName[comboBox1.SelectedIndex];
            textBox2.Text = str;
            str = "";
            str += Var.JncArr[comboBox1.SelectedIndex, 0];
            textBox3.Text = str;
            str = "";
            str += Var.JncArr[comboBox1.SelectedIndex, 1];
            textBox4.Text = str;
        }

        private void button5_Click(object sender, EventArgs e)
        {
            double x, y;
            try
            {
                x = double.Parse(textBox3.Text);
                y = double.Parse(textBox4.Text);
                Var.JncArr[comboBox1.SelectedIndex, 0] = x;
                Var.JncArr[comboBox1.SelectedIndex, 1] = y;
            }
            catch
            {
                MessageBox.Show("Invalid Entry, Must be Numeric", "Error");
            }
        }

        private void comboBox2_SelectedIndexChanged(object sender, EventArgs e)
        {
            textBox7.Text = Var.StrName[comboBox2.SelectedIndex];
            comboBox3.SelectedIndex = Var.StrArr[comboBox2.SelectedIndex, 0];
            comboBox4.SelectedIndex = Var.StrArr[comboBox2.SelectedIndex, 1];
            string str = "";
            str += Var.StrArr[comboBox2.SelectedIndex, 2];
            textBox5.Text = str;
            
        }

        private void button7_Click(object sender, EventArgs e)
        {
            textBox7.Text = Var.StrName[comboBox2.SelectedIndex];
            comboBox3.SelectedIndex = Var.StrArr[comboBox2.SelectedIndex, 0];
            comboBox4.SelectedIndex = Var.StrArr[comboBox2.SelectedIndex, 1];
            string str = "";
            str += Var.StrArr[comboBox2.SelectedIndex, 2];
            textBox5.Text = str;
            
        }

        private void button6_Click(object sender, EventArgs e)
        {
            int id1, id2;
            try
            {
                id1 = comboBox3.SelectedIndex;
                id2 = comboBox3.SelectedIndex;
                Var.StrArr[comboBox2.SelectedIndex, 0] = id1;
                Var.StrArr[comboBox2.SelectedIndex, 1] = id2;
                Var.StrArr[comboBox2.SelectedIndex, 2] = int.Parse(textBox5.Text);
                Var.StrName[comboBox2.SelectedIndex] = textBox7.Text;
            }
            catch
            {
                MessageBox.Show("Invalid Entry, Must be Numeric", "Error");
            }
        }

        private void DoneBtt_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    
    }
}
